﻿package com.wandian.view.mediator.account
{
	import com.wandian.controller.AccountCommand;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.SwfDataProxy;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZLoadingData;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.GolbalTimer;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.CardManage;
	import com.wandian.view.components.ui.LevelManage;
	import com.wandian.view.components.ui.MaskTipPanel;

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;

	/**
	 * 个人概况
	 * @author long
	 * @QQ 108232706
	 * @version 1.0
	 */
	public class InfomationMediator extends Mediator
	{
		private var _playerVo:PlayerVo;
		private var _global:GameData;
		private var _mcLevel:LevelManage;
		public static const NAME:String="InfomationMediator";

		public function InfomationMediator(viewComponent:Object=null, playerVo:PlayerVo=null)
		{
			this._global=GameData.getInstance();
			this._mcLevel=new LevelManage();
			this._playerVo=playerVo;
			super(NAME, viewComponent);
			return;
		}

		override public function onRegister():void
		{
			this.mcInfo.rankName_txt.text=GameData.tip["WEALTH_RANK_NAME"] + "：";
			this.mcInfo.levelName_txt.text=GameData.tip["GOLDLEVELNAME"] + "：";
			this.mcInfo.goldName_txt.text=GameData.tip["BUYIN_SUMGOLD_NAME"] + "：";
			this.mcInfo.midName_txt.text=GameData.tip["IDNAME"] + "：";
			this.mcInfo.nameName_txt.text=GameData.tip["NICKNAME"] + "：";
			this.mcInfo.bankName_txt.text=GameData.tip["DEPOSIT_BANK"] + "：";
			this.mcInfo.rank_txt.text=this._playerVo.rank.toString();
//			this.mcInfo.gold_txt.text=this._playerVo.gold.toString();
			this.mcInfo.mid_txt.text=this._playerVo.userid.toString();
			this.mcInfo.name_txt.text=this._playerVo.name.toString();
			if (this._global.userInfo.userVo.userid == this._playerVo.userid)
			{
				this.mcInfo.bank_txt.text=this._playerVo.bankAssets.toString();
			}
			else
			{
				this.mcInfo.bank_txt.text=GameData.tip["SECRET"];
			}
			this.mcInfo.cardsName_txt.text=GameData.tip["MAX_CARDS"] + ":";
			this.mcInfo.winPointName_txt.text=GameData.tip["MAX_WIN_POINT"] + ":";
			this.mcInfo.maxGoldName_txt.text=GameData.tip["MAX_ASSETS"] + ":";
			this.mcInfo.sumGameName_txt.text=GameData.tip["SUM_GAME_NUM"] + ":";
			this.mcInfo.winGameName_txt.text=GameData.tip["WIN_GAME_NUM"] + ":";
			this.mcInfo.ratioName_txt.text=GameData.tip["WIN_RATIO"] + ":";
			this._mcLevel.updateLevel(this.mcInfo["level_mc"], this._playerVo.level, false);
			if (_playerVo.headImage != null)
			{
				CLZLoadIcon.addBytesIcon(this.mcInfo, _playerVo.headImage, 50, 50, 18.4, 22.6, "InitPicGirlIcon", false, false);
			}
			else
			{
				if (this._playerVo.sex == 1)
				{
					CLZLoadIcon.addIcon(this.mcInfo, this._playerVo.icon, 50, 50, 18.4, 22.6, "InitPicGirlIcon", false, false);
				}
				else
				{
					CLZLoadIcon.addIcon(this.mcInfo, this._playerVo.icon, 50, 50, 18.4, 22.6, "InitPicBoyIcon", false, false);
				}
			}
			this.sendNotification(CLZNoticeName.PLAYER_INFOMATION_REQ, this._playerVo.userid);
			if (this._playerVo.userid == this._global.userInfo.userVo.userid)
			{
				CLZButton.setButton(this.mcInfo.matchShare_btn, GameData.tip["CORNUCOPIA_LIST_SHARE_ME"]);
				CLZButton.setButton(this.mcInfo.hightShare_btn, GameData.tip["CORNUCOPIA_LIST_SHARE_ME"]);
				CLZButton.setButton(this.mcInfo.numShare_btn, GameData.tip["CORNUCOPIA_LIST_SHARE_ME"]);
			}
			else
			{
				CLZButton.setButton(this.mcInfo.matchShare_btn, GameData.tip["SHARE_TO_OTHER"]);
				CLZButton.setButton(this.mcInfo.hightShare_btn, GameData.tip["SHARE_TO_OTHER"]);
				CLZButton.setButton(this.mcInfo.numShare_btn, GameData.tip["SHARE_TO_OTHER"]);
			}
			this.mcInfo.matchShare_btn.visible=false;
			this.mcInfo.hightShare_btn.visible=false;
			this.mcInfo.numShare_btn.visible=false;
			this.mcInfo.matchShare_btn.addEventListener(MouseEvent.CLICK, this.onMatchShare);
			this.mcInfo.hightShare_btn.addEventListener(MouseEvent.CLICK, this.onHightShare);
			this.mcInfo.numShare_btn.addEventListener(MouseEvent.CLICK, this.onNumShare);
			CLZLoadingData.show(this.mcInfo);
			return;
		}

		private function onMatchShare(event:MouseEvent):void
		{
//            JSFUN.shareMatchPlayerFunc(this._playerVo.userid);
			return;
		}

		private function onHightShare(event:MouseEvent):void
		{
//            JSFUN.shareHightCardFunc(this._playerVo.userid);
			return;
		}

		private function onNumShare(event:MouseEvent):void
		{
//            JSFUN.shareWinGameFunc(this._playerVo.userid);
			return;
		}

		override public function listNotificationInterests():Array
		{
			return [CLZNoticeName.PLAYER_INFOMATION_RES];
		}

		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case CLZNoticeName.PLAYER_INFOMATION_RES:
				{
					CLZLoadingData.hide(this.mcInfo);
					var data:Object=notification.getBody();
					var arrUserInfo:Array=null;
					var cardMgr:CardManage=null;
					var arrCard:String=null;
					var index:int=0;
					if (data.error != 0)
					{
						var data:Object={okNoticeName: CLZNoticeName.TIPMEDIATOR_HIDE_WINDOWS_TIP, tip: "获取该玩家信息失败！", tipTitle: "温馨提示", isCancel: false, okTip: "OK", cancelTip: "", isSendClose: true};
						this.sendNotification(CLZNoticeName.TIPMEDIATOR_SHOW_WINDOWS_TIP, data);
					}
					else
					{
						arrUserInfo=data.arr;
						this.mcInfo.winPoint_txt.text=int(arrUserInfo[1]) + "";
						this.mcInfo.maxGold_txt.text=int(arrUserInfo[2]) + "";
						this.mcInfo.sumGame_txt.text=int(arrUserInfo[3]) + "";
						this.mcInfo.winGame_txt.text=int(arrUserInfo[4]) + "";
						this.mcInfo.gold_txt.text=int(arrUserInfo[5]) + "";
						this.mcInfo.rank_txt.text=int(arrUserInfo[6]) + "";

						this.mcInfo.ratio_txt.text=Number(int(arrUserInfo[3]) / int(arrUserInfo[4]) * 100).toFixed(2) + "%";
						if (arrUserInfo[0].length < 10)
						{
							return;
						}
						arrCard=arrUserInfo[0];
						index=0;
						while (index < 5)
						{

							cardMgr=new CardManage(GameData.getMovieClip("Card"));
							cardMgr.showCard(arrCard.substr(index * 2, 2), false);
							cardMgr.width=23;
							cardMgr.height=30;
							cardMgr.x=index * cardMgr.width + index * 2 + 252;
							cardMgr.y=253;
							this.mcInfo.addChild(cardMgr);
							index=index + 1;
						}
					}

					break;
				}
				default:
				{
					break;
				}
			}
			return;
		}

		private function get mcInfo():MovieClip
		{
			return viewComponent as MovieClip;
		}

	}
}
